import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
// @ts-ignore
import Components from 'unplugin-vue-components/vite'
// @ts-ignore
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
// @ts-ignore
import { SvgBuilder } from './src/plugins/SvgBuilder'
import * as path from 'path'

// https://vitejs.dev/config/
export default ({ mode }) => defineConfig({
  server: {
    port: 3000,
    proxy: {
      '/api': {
        // target: 'http://localhost:30012',
        target: loadEnv(mode, process.cwd()).VITE_API_DEV_SERVER_PREFIX,
        ws: false,
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  },
  plugins: [
    vue(),
    vueJsx(),
    Components({
      resolvers: [
        AntDesignVueResolver({ importStyle: 'less' })
      ]
    }),
    SvgBuilder('./src/assets/icons/svg/')
  ],
  css: {
    preprocessorOptions: {
      less: {
        modifyVars: {
          '@primary-color': '#08a6fc',
          dark: false
        },
        javascriptEnabled: true
      }
    }
  },
  resolve: {
    // 配置路径别名
    alias: {
      '@': path.resolve(__dirname, './src')
    }
  }
})
